package com.example.administrator.officeplatform.Audit;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.officeplatform.R;
import com.example.administrator.officeplatform.bean.CostInfo;
import com.example.administrator.officeplatform.bean.ExpenseCostFormDetailVoInfo;
import com.example.administrator.officeplatform.bean.ReimbursementVoInfo;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/12/23.
 */

public class ExpenseCostAdapter extends RecyclerView.Adapter{
//    public static interface OnRecyclerViewListener {
//        void onItemClick(int position);
//
//        boolean onItemLongClick(int position);
//    }

//    private OnRecyclerViewListener onRecyclerViewListener;
//
//    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
//        this.onRecyclerViewListener = onRecyclerViewListener;
//    }

    private List<CostInfo> list = new ArrayList<>();
    private Context mContext;

    public ExpenseCostAdapter(List<CostInfo> list, Context mContext) {
        this.list = list;
        this.mContext=mContext;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_expensecost, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final PersonViewHolder personViewHolder = (PersonViewHolder) holder;
        personViewHolder.position = position;
        CostInfo expenseCostFormDetailVoInfo= list.get(position);
        DecimalFormat format = new DecimalFormat("0.00");
        String money = format.format(expenseCostFormDetailVoInfo.getMoney());
        String LoanNum = format.format(expenseCostFormDetailVoInfo.getLoanNum());

        personViewHolder.tv_name.setText("供应商/员工名称:  "+expenseCostFormDetailVoInfo.getSupplierName());
        personViewHolder.tv_xm.setText("费用项目:  "+expenseCostFormDetailVoInfo.getCostProject());
        personViewHolder.tv_zq.setText("结算归属周期:  "+expenseCostFormDetailVoInfo.getSettlementCycle());
        personViewHolder.tv_type.setText("类别:  "+expenseCostFormDetailVoInfo.getCategoryName());
        personViewHolder.tv_bxbl.setText("报销比例:  "+expenseCostFormDetailVoInfo.getReimbursementProportion());
        personViewHolder.tv_money.setText("金额:"+"￥"+money);
        if(expenseCostFormDetailVoInfo.getIsLoan()==1){
            personViewHolder.tv_isjk.setText("是否有借款:  否");
        }else if(expenseCostFormDetailVoInfo.getIsLoan()==2){
            personViewHolder.tv_isjk.setText("是否有借款:  是");
        }
        personViewHolder.tv_kljkd.setText("关联借款单:  "+expenseCostFormDetailVoInfo.getLoanCode());
        personViewHolder.tv_jks.setText("剩余借款金额:"+"￥  "+LoanNum);
        personViewHolder.tv_fybm.setText("费用所属部门:  "+expenseCostFormDetailVoInfo.getDepartmentName());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class PersonViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public int position;
        public TextView tv_name,tv_xm,tv_zq,tv_type,tv_bxbl,tv_money,tv_isjk
                ,tv_kljkd,tv_jks,tv_fybm;

        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_name = (TextView)itemView.findViewById(R.id.tv_name);
            tv_xm = (TextView)itemView.findViewById(R.id.tv_xm);
            tv_zq = (TextView)itemView.findViewById(R.id.tv_zq);
            tv_money = (TextView)itemView.findViewById(R.id.tv_money);
            tv_type = (TextView)itemView.findViewById(R.id.tv_type);
            tv_bxbl = (TextView)itemView.findViewById(R.id.tv_bxbl);
            tv_isjk= (TextView)itemView.findViewById(R.id.tv_isjk);
            tv_kljkd= (TextView)itemView.findViewById(R.id.tv_kljkd);
            tv_jks= (TextView)itemView.findViewById(R.id.tv_jks);
            tv_fybm = (TextView)itemView.findViewById(R.id.tv_fybm);

            rootView = itemView.findViewById(R.id.ll);
//            rootView.setOnClickListener(this);
//            rootView.setOnLongClickListener(this);
        }

//        @Override
//        public void onClick(View v) {
//            if (null != onRecyclerViewListener) {
//                onRecyclerViewListener.onItemClick(position);
//            }
//        }
//
//        @Override
//        public boolean onLongClick(View v) {
//            if (null != onRecyclerViewListener) {
//                return onRecyclerViewListener.onItemLongClick(position);
//            }
//            return false;
//        }
    }
}
